<template>
    <div>
        <h1 style="text-align: center; margin-top: 30px; margin-bottom: 30px">质量巡检</h1>
<el-form  :model="search" label-width="110px">
  <el-form-item label="项目名称">
    <el-select v-model="search.p_id" placeholder="项目名称" style="width:150px">
        <el-option value="" >项目名称</el-option>
        <el-option v-for="item1 in getName" :key="item1.project_name" 
        :label="item1.project_name" :value="item1.id">
        </el-option>
      </el-select>
  </el-form-item>
  <el-form-item label="检查部位">
    <el-input v-model="search.check_part" style="width:200px"></el-input>
  </el-form-item>
  <el-form-item label="巡检编号">
     <el-input v-model="search.id" placeholder="保存后自动生成" style="width:200px" disabled></el-input>
  </el-form-item>
  <el-form-item label="检查日期">
    <el-col :span="11">
      <el-date-picker type="date" placeholder="选择日期" v-model="search.check_date" style="width:200px"></el-date-picker>
    </el-col>
  </el-form-item>
  <el-form-item label="质检员">
     <el-select v-model="search.qualityer_id" placeholder="检查人" style="width:150px">
        <el-option value="" >检查人</el-option>
        <el-option v-for="item in user" :key="item.name"  :label="item.name" :value="item.id">
        </el-option>
      </el-select>
  </el-form-item>
  <el-form-item label="检查情况" >
    <el-input v-model="search.check_situation"></el-input>
  </el-form-item>
  <el-form-item label="纠正预防措施">
    <el-input v-model="search.corretive_preventive_measure"></el-input>
  </el-form-item>
  <el-form-item label="备注">
    <el-input v-model="search.comment"></el-input>
  </el-form-item>
   <!-- 文件上传 -->
  <el-form-item label="附件" class="item">
    <multi-file-upload style="width:100%;margin:20px auto"
    title="附件"
    action="http://localhost/uploads"
    :params="{folder:'tenderPurchasePlan'}"
    :headers="{token:token}"
    :show-button="!checkRoute"
    @uploadSuccess="handleUploadSuccess"
    :parent-file-list="fileList"
    ></multi-file-upload>
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click="add">立即创建</el-button>
    <el-button>取消</el-button>
  </el-form-item>
</el-form>
    </div>
</template>
<script>
import axios from "axios";
import {DateUtil} from "../../model/common/DateUtil";
export default {
  data() {
    return {
      //文件上传
      tenderPurchasePlan:{ 
        id:'',
        date:DateUtil.today(),
        planEditor:sessionStorage.getItem('realName')
        },
      search:{}, //表格数据
      user:{},
      getName:{},
      update_user:sessionStorage.getItem('realName'),
      
    };
  },
  methods: {
    // 下拉框查询
   getuser(){
      axios.get(`http://localhost/GetList/getUser`).then((response) => {
        this.user = response.data;
      });
   },
    getname(){
        axios.get(`http://localhost/GetList/getName`).then((response) => {
          this.getName = response.data;
      });
   },
   // 添加
   add(){
        console.log(this.tenderPurchasePlan)
       let attach_ids=this.tenderPurchasePlan.attachemeIds
       console.log(attach_ids)
       axios.get(`http://localhost/GetList/add1`,{
           params:{
               "attach_ids":attach_ids,
               "update_user":this.update_user,
               "p_id":this.search.p_id,
               "check_part":this.search.check_part,
               "check_date":this.search.check_date,
               "qualityer_id":this.search.qualityer_id,
               "check_situation":this.search.check_situation,
               "corretive_preventive_measure":this.search.corretive_preventive_measure,
               "comment":this.search.comment,
           }
       });
       //location.reload();
   },
   //文件上传
   handleUploadSuccess(ids,fileList){
    console.log(fileList);
    this.tenderPurchasePlan.attachemeIds=ids;
     },
  },
  computed:{
    token:{
      get(){
        return this.$store.state.token
        }
        },
        checkRoute(){
          return Object.keys(this.$route.params).length!=0
          }
          },
  created() {
   this.getuser();
   this.getname();
  },
};
</script>